
#include "Record.h"
#include "BPlusTree.h"
#include <stdlib.h>
#include <iostream.h> 

int main () {

	BPlusTree myTree;
	myTree.Create ("/var/tmp/myTree", Int);

	for (int i = 0; i < 10000; i++) {
		if (i % 1000 == 0) {
			cerr << ".";
		}	
		char foo[10];
		*((int *) foo) = lrand48 ();
		myTree.Insert (foo, 2);
	}

	myTree.Close ();
	myTree.Open ("/var/tmp/myTree");

	for (int i = 0; i < 10000; i++) {
		if (i % 1000 == 0) {
			cerr << ".";
		}	
		char foo[10];
		*((int *) foo) = lrand48 ();
		myTree.Insert (foo, 2);
	}

	int numReturned;
	char foo[10];
	*((int *) foo) = -99999;
	IndexRecord *result = myTree.GetPage (foo, numReturned);
	for (int i = 0; i < numReturned; i++) {
		cout << result[i].GetInt (0) << "\n";
	}
	delete [] result;

	while (1) {
		IndexRecord *result = myTree.GetNext (numReturned);
		if (result == 0)
			break;
		for (int i = 0; i < numReturned; i++) {
			cout << result[i].GetInt (0) << "\n";
		}
		delete [] result;
	}
}
